﻿using Smobiler.Core;
using Smobiler.Core.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using DAL;
using FubiManger.Controls;

namespace FubiManger.UI
{
    partial class PacketForm : Smobiler.Core.Controls.MobileForm
    {
        public PacketForm() : base()
        {
            //This call is required by the SmobilerForm.
            InitializeComponent();
        }
        public string merchantid { get; set; }
        List<ms_packet> packetlist = new List<ms_packet>();
        private void panclose_Press(object sender, EventArgs e)
        {
            this.Close();
        }
        /// <summary>
        /// 发红包
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void panadd_Press(object sender, EventArgs e)
        {
            AddpacketForm frm = new AddpacketForm();
            frm.merchantid = merchantid;
            this.Form.Show(frm, true, (obj, args) =>
            {
                lbl_packet.Visible = true;
                lbl_bpacket.Visible = false;
                if (panpacket.Controls.Count > 0)
                    panpacket.Controls.Clear();
                packetlist = packetDal.Querybymerchantid(merchantid,"1");
                panpacket.Height = packetlist.Count * 118;
                for (int i = 0; i < packetlist.Count; i++)
                {
                    packetcontrol con = new packetcontrol();
                    con.starttime = Convert.ToDateTime(packetlist[i].p_starttime);//起始时间
                    con.level = packetlist[i].p_level;//等级
                    con.endtime = Convert.ToDateTime(packetlist[i].p_endtime);//结束时间
                    con.way = packetlist[i].p_way;//方式
                    con.rank = packetlist[i].p_rank;//范围
                    con.moeny = packetlist[i].p_money;//红包
                    con.p_id = packetlist[i].p_id;
                    panpacket.Controls.Add(con);

                }
            });
        }
        /// <summary>
        /// 未结束红包
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnkill_Press(object sender, EventArgs e)
        {
            lbl_packet.Visible = true;
            lbl_bpacket.Visible = false;
            if (panpacket.Controls.Count > 0)
                panpacket.Controls.Clear();
            packetlist = packetDal.Querybymerchantid(merchantid,"1");
            panpacket.Height = packetlist.Count * 118;
            for (int i = 0; i < packetlist.Count; i++)
            {
                packetcontrol con = new packetcontrol();
                con.starttime = Convert.ToDateTime(packetlist[i].p_starttime);//起始时间
                con.level = packetlist[i].p_level;//等级
                con.endtime = Convert.ToDateTime(packetlist[i].p_endtime);//结束时间
                con.way = packetlist[i].p_way;//方式
                con.rank = packetlist[i].p_rank;//范围
                con.moeny = packetlist[i].p_money;//红包
                con.p_id = packetlist[i].p_id;
                panpacket.Controls.Add(con);

            }
        }
        /// <summary>
        /// 往期红包
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btngroup_Press(object sender, EventArgs e)
        {
            lbl_bpacket.Visible = true;
            lbl_packet.Visible = false;
            if (panpacket.Controls.Count > 0)
                panpacket.Controls.Clear();
            packetlist = packetDal.Querybymerchantidend(merchantid,"1");
            panpacket.Height = packetlist.Count * 118;
            for (int i = 0; i < packetlist.Count; i++)
            {
                packetcontrol con = new packetcontrol();
                con.starttime = Convert.ToDateTime(packetlist[i].p_starttime);//起始时间
                con.level = packetlist[i].p_level;//等级
                con.endtime = Convert.ToDateTime(packetlist[i].p_endtime);//结束时间
                con.way = packetlist[i].p_way;//方式
                con.rank = packetlist[i].p_rank;//范围
                con.moeny = packetlist[i].p_money;//红包
                con.p_id = packetlist[i].p_id;
                panpacket.Controls.Add(con);

            }
        }
        /// <summary>
        /// 添加红包
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pan_add_Press(object sender, EventArgs e)
        {

        }

        private void PacketForm_Load(object sender, EventArgs e)
        {
            lbl_packet.Visible = true;
            lbl_bpacket.Visible = false;
            packetlist = packetDal.Querybymerchantid(merchantid,"1");
            panpacket.Height = packetlist.Count * 118;
            for (int i = 0; i < packetlist.Count; i++)
            {
                packetcontrol con = new packetcontrol();
                con.starttime = Convert.ToDateTime(packetlist[i].p_starttime);//起始时间
                con.level = packetlist[i].p_level;//等级
                con.endtime = Convert.ToDateTime(packetlist[i].p_endtime);//结束时间
                con.way = packetlist[i].p_way;//方式
                con.rank = packetlist[i].p_rank;//范围
                con.moeny = packetlist[i].p_money;//红包
                con.p_id = packetlist[i].p_id;
                panpacket.Controls.Add(con);

            }
        }
    }
}